package model.tokens;

import util.reflection.Reflection;
import model.semantics.Node;
import model.semantics.Operation;
import model.semantics.OperatorNode;

/**
 * Factory class to create nodes from tokens. Called from FunctionalToken.
 * @author Sterling Dorminey
 */
public class NodeFactory {
	@SuppressWarnings("unchecked")
	public static<T> Node<T> createOperatorNode(int order, String[] callArgs, Node<T>[] values) {
		Operation<T> op;
		if(order < 0) {
			op = (Operation<T>) Reflection.createInstance(callArgs[0], values.length);
		} else {
			op = (Operation<T>) Reflection.createInstance(callArgs[0]);
		}
		
		return new OperatorNode<T>(op, values);
	}
	
	@SuppressWarnings("unchecked")
	public static<T> Node<T> createNode(int order, String[] callArgs, Node<T>[] values) {
		Node<T> node = (Node<T>) Reflection.createInstance(callArgs[0], (Object []) values);
		
		return node;
	}
}
